﻿
#Copyright (C) 2011 Daniele Simonetti
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

### PySide ###
from PySide import QtCore, QtGui

import gettext, locale, os, sys
machine_locale = locale.getdefaultlocale()[0]
locale_dir = '/usr/share/locale'
if not os.path.exists(locale_dir):
    locale_dir = os.path.join(sys.path[0], 'locale')
t = gettext.translation('epes', locale_dir, [machine_locale])
_ = t.gettext


#### CUSTOM TABLE VIEW ####
class MyTableView(QtGui.QTableView):
  def __init__(self, parent=None):
    super(MyTableView, self).__init__(parent)    
    
  # PAINT TABLE
  def paintEvent(self, ev): 
    super(MyTableView, self).paintEvent(ev)     
    if self.model().rowCount() == 0:
        painter = QtGui.QPainter(self.viewport())
        if not painter.isActive():
            return
            
        ev.accept()
        painter.save()
        painter.setRenderHint(QtGui.QPainter.Antialiasing, True)
        lines = [':(', _("It's sad here"), _("Add some shows")]
        y = self.y() + 10
        big_font = QtGui.QFont(self.font().family(), 24)        
        color = painter.pen().color().lighter(300)
        painter.setPen( QtGui.QPen(color) )
        painter.setFont(big_font)
        for line in lines:
            fm = painter.fontMetrics()
            br = fm.boundingRect(line)
            x = self.x() + self.width()/2 - br.width()/2  
            painter.drawText(x,y,line)
            y += fm.height() + 10   
        painter.restore()   
